<?php

namespace app\controller\admin\cnf;

use app\bll\ComponentEventList as BllComponentEventList;
use app\bll\ComponentEvent as BllComponentEvent;
use core\controller\AdminBase;
use Exception;
use support\View;
use app\bll\Hook as BllHook;

/**
 * 组件 事件组
 */
class ComponentEvent extends AdminBase
{


    public function index()
    {
        $BllComponentEvent = new BllComponentEvent();
        $events = $BllComponentEvent->paginator(
            title: request()->get('title', ''),
            ident: request()->get('ident', ''),
        );
        View::assign('events', $events);
        return $this->view();
    }

    /**
     * 安装实践组
     *
     * @return void
     */
    public function install()
    {
        if (is_post()) {
            try {
                $bllComponentEvent = new BllComponentEvent();
                $bllComponentEvent->install();
            } catch (Exception $ex) {
                return $this->error($ex->getMessage());
            }
            return $this->success();
        } else {
            return $this->view(frame: false);
        }
    }

    public function handleUpgrade()
    {
        if (request()->isPost()) {
            try {
                $bllComponentEvent = new BllComponentEvent();
                $bllComponentEvent->handleUpgrade(request()->input('id'));
            } catch (Exception $ex) {
                return $this->error($ex->getMessage());
            }
            return $this->success();
        } else {
            return $this->view(frame: false);
        }
    }

    /**
     * 在线升级
     *
     * @return void
     */
    public function onlineUpgrade()
    {
        try {
            $bllComponentEvent = new BllComponentEvent();
            $bllComponentEvent->onlineUpgrade(request()->input('id'));
        } catch (Exception $ex) {
            return $this->error($ex->getMessage());
        }
        return $this->success();
    }

    public function unInstall()
    {
        try {
            $bllComponentEvent = new BllComponentEvent();
            $bllComponentEvent->unInstall(request()->input('id'));
        } catch (Exception $ex) {
            return $this->error($ex->getMessage());
        }
        return $this->success();
    }
   
}
